<script setup>
	import { defineProps, onMounted, ref } from 'vue'
	import { http } from '@/utils/http.js'
	import { onLoad, onShow } from '@dcloudio/uni-app'
	import { parseTime } from '@/utils/index.js'

	const max = ref(0)
	const time = ref(0)
	const balance = ref(0)
	async function getBalance() {
		const res = await http.request({
			url: '/api//bidding/withdrawalPage',
			method: 'POST',
			data: {},
		})
		console.log(res)
		max.value = res.data.sum_money
		time.value = res.data.num_times
		balance.value = res.data.transaction_balance
		cashBalance.value = res.data.ali
		cashName.value = res.data.tx_name
	}

	const cashMoney = ref()
	const cashBalance = ref()
	const cashName = ref()
	async function goCash() {
			// uni.utils.toast('内测期间暂未开放')
		if (!cashMoney.value) {
			uni.utils.toast('请填写提现金额')
			return
		}
		// if (Number(cashMoney.value) < Number(min.value)) {
		// 	uni.utils.toast('提现金额不可小于最低额度')
		// 	return
		// }
		if (Number(cashMoney.value) > Number(max.value)) {
			uni.utils.toast('提现金额不可大于最大额度')
			return
		}
		if (Number(cashMoney.value) > Number(balance.value)) {
			uni.utils.toast('提现卡尘不可大于账户可提现卡尘额度')
			return
		}
		if (Math.floor(Number(cashMoney.value)) != Number(cashMoney.value)) {
			uni.utils.toast('提现卡尘不可是小数')
			return
		}
		if (!cashBalance.value) {
			uni.utils.toast('请填写支付宝账户')
			return
		}
		if (!cashName.value) {
			uni.utils.toast('请填写收款账户真实名称')
			return
		}
		const res = await http.request({
			url: '/api/bidding/withdrawalPost',
			method: 'POST',
			data: {
				money: cashMoney.value,
				tx_name: cashName.value,
				ali: cashBalance.value,
				withdrawal_type: 1,
			},
		})
		if (res.st == 1) {
			cashMoney.value = ''
			cashBalance.value = ''
			cashName.value = ''
			getBalance()
			uni.navigateTo({
				url: '/transactionPage/cashsuccess/index',
			})
		} else if (res.st == -2) {
			namepopup.value.open('center')
		} else {
			uni.utils.toast(res.msg)
		}
	}

	function detail() {
		uni.navigateTo({
			url: '/transactionPage/treasuredetail/index',
		})
	}

	const namepopup = ref()
	function goRealName() {
		namepopup.value.open('center')
		uni.navigateTo({
			url: '/minePage/authentication/index',
		})
	}

	onMounted(() => {
		getBalance()
	})
</script>

<template>
	<view class="deal-contant">
		<view class="top-banner">
			<view class="xingshi">
				<text class="" style="font-size: 22rpx">我的卡尘</text>
				<text
					style="margin-right: 40rpx; font-size: 22rpx"
					@click="detail"
					>卡尘明细</text
				>
			</view>
			<view class="xingshi-balance">
				<image src="@/static/xinshi.png"></image>
				<text class="">{{ balance }}</text>
			</view>
			<view class="xingshi-about">
				<view class="">48小时内最多结算{{time}}次，最高累计{{max}} </view>
				<!-- <view class="rule">
					<text class="">规则</text>
					<image
						src="https://ojqn.wm2177.com/wechat_imgs/transition/rule.png"
						class=""
					></image>
				</view> -->
			</view>
		</view>

		<view class="tit-num">
			<text class="">结算数量</text>
			<!-- <text class="all">全部</text> -->
		</view>
		<view class="num">
			<input
				v-model="cashMoney"
				class="input"
				type="number"
				placeholder="请输入结算数量"
			/>
		</view>
		<view class="tit-num">
			<text class="">结算方式</text>
		</view>

		<view class="xingshi-balance payment">
			<image
				style="margin-left: 0"
				src="https://ojqn.wm2177.com/wechat_imgs/transition/Alipay.png"
			></image>
			<text class="">结算至支付宝</text>
			<image
				src="https://ojqn.wm2177.com/wechat_imgs/transition/deal-success.png"
				class="select"
			></image>
		</view>

		<view class="pay-count">
			<text class="count-id">支付宝账号</text>
			<input
				class=""
				style="margin-top: 30rpx"
				type="number"
				v-model="cashBalance"
				placeholder="请输入支付宝账号"
			/>
		</view>
		<view class="pay-count">
			<text class="count-id">支付宝姓名</text>
			<input
				class=""
				style="margin-top: 30rpx"
				type="text"
				placeholder="请输入实名的姓名"
				v-model="cashName"
			/>
		</view>
		<view class="pay-btn" @click="goCash">
			<text class="">申请结算</text>
		</view>

		<!-- 实名制出层 -->
		<uni-popup ref="namepopup" type="center">
			<view class="namepopup-content">
				<view class="namepopup-title"> 提示 </view>
				<view class="namepopup-content-tow">
					鉴于您是平台的优质用户，为了能给您提供更好的服务体验，请先完成实名制认证。</view
				>
				<view class="namepopup-button">
					<view class="" @click="namepopup.close('center')">
						再想一下
					</view>
					<view class="" @click="goRealName"> 确认实名 </view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<style lang="scss" scoped>
	.deal-contant {
		height: 100%;
		background-color: #fff;
	}

	.top-banner {
		background: url(https://ojqn.wm2177.com/wechat_imgs/transition/top-banner.png);
		background-size: 100%;
		width: 700rpx;
		height: 280rpx;
		margin: 30rpx auto;
		margin-top: 0;
	}
	.xingshi {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 40rpx 0rpx 24rpx 40rpx;
	}
	.xingshi-balance {
		text-align: center;
		display: flex;
		align-items: center;
		font-size: 60rpx;

		font-weight: 600;
		image {
			width: 68rpx;
			height: 52rpx;
			margin: 0 10rpx 0 40rpx;
		}
	}
	.xingshi-about {
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 22rpx;
		padding: 48rpx 30rpx 0 40rpx;
		image {
			width: 22rpx;
			height: 22rpx;
			// vertical-align: middle;
			margin-left: 5rpx;
			margin-top: 5rpx;
			// margin: 20rpx;
		}
		.rule {
			display: flex;
		}
	}
	.tit-num {
		display: flex;
		font-size: 28rpx;
		color: #3d3d3d;
		margin: 40rpx;
		font-weight: 600;
		.all {
			font-size: 26rpx;
			color: #7c7c7c;
			margin-left: 75%;
		}
	}
	.num {
		font-size: 30rpx;
		font-weight: 600;
		color: #3d3d3d;
		background-color: #f7f7f7;
		width: 696rpx;
		margin: 30rpx;
		height: 72rpx;
		border-radius: 12rpx;
	}
	.input {
		padding-top: 14rpx;
		font-size: 28rpx;
		font-weight: 600;
		padding-left: 40rpx;
	}
	.payment {
		margin: 30rpx;
		font-size: 30rpx;
		line-height: 84rpx;
		image {
			width: 48rpx;
			height: 48rpx;
		}
		.select {
			margin-left: 57%;
			image {
				width: 36rpx;
				height: 36rpx;
			}
		}
	}
	.pay-count {
		// display: flex;
		font-size: 26rpx;
		font-weight: 500;
		margin: 40rpx;
	}
	.count-id {
	}

	.pay-btn {
		width: 700rpx;
		height: 90rpx;
		text-align: center;
		line-height: 90rpx;
		font-size: 28rpx;
		color: #3d3d3d;
		font-weight: 600;
		margin: 50rpx auto;
		background-color: #ffe60f;
		border-radius: 40rpx;
	}
	.namepopup-content {
		width: 600rpx;
		height: 404rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		border-radius: 36rpx;
		background-color: #fff;
		.namepopup-title {
			height: 114rpx;
			border-bottom: 1px solid #d8d8d8;
			text-align: center;
			font-size: 40rpx;
			line-height: 114rpx;
		}
		.namepopup-content-tow {
			height: 164rpx;
			padding-top: 32rpx;
			box-sizing: border-box;
			text-align: center;
			font-size: 28rpx;
			color: #9b9b9d;
		}
		.namepopup-button {
			display: flex;
			align-items: center;
			justify-content: space-between;
			// margin-top: 26rpx;
			view {
				width: 234rpx;
				height: 80rpx;
				background-color: $transaction-color;
				border-radius: 40rpx;
				text-align: center;
				font-size: 26rpx;
				font-weight: 700;
				line-height: 80rpx;
				&:first-child {
					background-color: #eee;
				}
			}
		}
	}
</style>
